package com.supreme.commontools;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;

import java.io.File;

public class SupremeFileUtils {

    public static JSONObject resourceToJson() {
        return null;
    }

    public static String getProjectDir() {
        return System.getProperty("user.dir");
    }

    public static String getParentProjectDir() {
        final String projectDir = System.getProperty("user.dir");
        return StringUtils.substringBeforeLast(projectDir, File.separator);
    }

    public static String getPathOfProjectDir(String path) {
        return getProjectDir() + File.separator + path;
    }

    public static String getPathOfParentProjectDir(String path) {
        return getParentProjectDir() + File.separator + path;
    }

    public static File createNewFile(String pathName) {
        File file = new File(pathName);
        if (file.exists()) {
            file.delete();
        } else {
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }
        }
        return file;
    }
}
